package org.example.myleet.p852;

public class Solution {
    public int peakIndexInMountainArray(int[] arr) {
        int l = 0, r = arr.length - 1;
        while (r - l > 1) {
            int mid = (r + l) / 2;
            if (arr[mid - 1] < arr[mid] && arr[mid] > arr[mid + 1]) {
                return mid;
            } else if (arr[mid - 1] < arr[mid]) {
                l = mid;
            } else {
                r = mid;
            }
        }
        return arr[l] < arr[r] ? r : l;
    }
}
